// api
import request from '@/utils/request';

export const getOrgInfo = async () =>
    request('/api/org/v1/functional/detail', {
        method: 'POST'
    });

export const getOrgList = async (params, fixedParams) =>
    request('/api/uc/org/v2/list', {
        method: 'POST',
        data: { ...params, ...fixedParams }
    });

// 获取公司及颜色的映射表（旧的）
// colorCode
export const getOrgColorMap = async () =>
    request('/api/org/v1/getReleasedOrgList', {
        method: 'POST',
        data: { organizationTypes: [2] }
    });

// 获取公司及颜色的映射表
export const getUsedOrgColorInfoList = async () =>
    request('/api/oa/workflow/organization/v1/getUsedOrgColorInfoList', {
        method: 'GET'
    });

export const getOrgTree = async () =>
    request('/api/uc/org/v1/format/all/list', {
        method: 'POST'
    });

// 获取权限管理的树
export async function getAuthTree() {
    return request('/api/uc/uac/v1/resource/menu/tree', {
        method: 'POST',
        data: {
            treeFlag: true
        }
    });
}

// 获取菜单树
export function getAuthData(params) {
    return request('/api/uc/uac/v1/resource/format/terminal/menu/tree', {
        method: 'POST',
        data: params
    });
}

// 获取员工信息2
export const getEmployeesByCode2 = params =>
    request('/api/org/v1/employeeInfo/queryEmployeeWihtLeader', {
        method: 'POST',
        data: {
            ...params
        }
    });
// 获取员工信息
export const getEmployeesByCode = params =>
    request('/api/org/v1/employeeInfo/queryEmployeeDetailInfoList', {
        method: 'POST',
        data: {
            ...params
        }
    });

// 获取集团/公司详情
export async function getCompanyDetail(organizationCode) {
    return request('/api/uc/org/company/v1/detail/getInfo', {
        method: 'POST',
        data: {
            organizationCode
        }
    });
}

// 公司变更到历史表
export async function changeCompanyToHistory(params) {
    return request('/api/oa/workflow/organization/v1/savecompanyhidata', {
        method: 'POST',
        data: params
    });
}

// 部门变更到历史表
export async function changeDepartmentToHistory(params) {
    return request('/api/oa/workflow/organization/v1/savedepartmenthidata', {
        method: 'POST',
        data: params
    });
}

// 机构删除前校验
export async function orgDeleteCheck(params) {
    return request('/api/org/v1/functional/deleteCheck', {
        method: 'POST',
        data: params
    });
}

// 岗位删除前校验
export async function postChangeDeleteCheck(dutyCode) {
    return request(`/api/org/v1/duty/can/delete/check/${dutyCode}`, {
        method: 'GET'
    });
}

// // 新增公司
// export async function addCompany(params) {
//     return request('/api/uc/org/company/v2/saveCompanyInfo', {
//         method: 'POST',
//         data: params
//     });
// }

// // 编辑公司
// export async function updateCompany(params) {
//     return request('/api/uc/org/company/v1/updateCompanyInfo', {
//         method: 'POST',
//         data: params
//     });
// }

// 获取部门详情
export async function getDepartmentDetail(organizationCode) {
    return request('/api/uc/org/department/v1/getInfo', {
        method: 'POST',
        data: {
            organizationCode
        }
    });
}

// 新增部门
export async function addDepartment(params) {
    return request('/api/uc/org/department/v1/save', {
        method: 'POST',
        data: params
    });
}

// 编辑部门
export async function updateDepartment(params) {
    return request('/api/uc/org/department/v1/update', {
        method: 'POST',
        data: params
    });
}

// 获取岗位详情
export async function getDutyDetail2(params) {
    return request('/api/oa/org/v1/duty/detail/info', {
        method: 'POST',
        data: params
    });
}

// 新增岗位
export async function addDuty(params) {
    // return request('/api/org/v1/organizationDuty/add', {
    return request('/api/oa/workflow/business/v1/duty/addToHiData', {
        method: 'POST',
        data: {
            operationType: 0,
            ...params
        }
    });
}

// 编辑岗位
export async function updateDuty(params) {
    // return request('/api/org/v1/organizationDuty/update', {
    return request('/api/oa/workflow/business/v1/duty/addToHiData', {
        method: 'POST',
        data: {
            operationType: 1,
            ...params
        }
    });
}

// 删除岗位
export async function delectDuty(params) {
    return request('/api/oa/workflow/business/v1/duty/addToHiData', {
        method: 'POST',
        data: params
    });
}

// 获取机构详情
export async function getOrganizationByCode(params) {
    return request('/api/org/v1/functional/detail', {
        method: 'POST',
        data: params
    });
}
// 岗位编制接口
export async function getOrgTotalPlanNum(params) {
    return request('/api/org/v1/functional/getOrgTotalPlanNum', {
        method: 'POST',
        data: params
    });
}
// 查询岗位列表
export const getPostList = params =>
    request('/api/uc/duty/v1/getList', {
        method: 'POST',
        data: params
    });

// 查询岗位列表 -- 发起调岗
export const getApplyPostList = params =>
    request('/api/uc/duty/v1/getListNoAuth', {
        method: 'POST',
        data: params
    });

// 更新权限菜单状态
export async function updateAuthStatus(params) {
    return request('/api/uc/uac/v1/authority/updateStatus', {
        method: 'POST',
        data: params
    });
}

// 批量更新权限菜单
export async function batchUpdateAuth(params) {
    return request('/api/uc/uac/v1/authority/batchUpdate', {
        method: 'POST',
        data: params
    });
}

// 更新权限到历史表
export async function updateAuthToHistory(params) {
    return request('/api/oa/workflow/authority/v1/savehidata', {
        method: 'POST',
        data: params
    });
}

// 获取授权树数据
export async function fetchDutyList(params) {
    return request('/api/org/v1/duty/queryDutyListByOrganization', {
        method: 'POST',
        data: params
    });
}

// 获取关联机构
export function getRelativeOrganizations(parentOrganizationCode) {
    return request(`/api/org/v1/relative/list/${parentOrganizationCode}`, {
        method: 'GET'
    });
}

// 获取关联机构的排序
export function getChildrenOrganizations(parentOrganizationCode) {
    return request(`/api/org/v1/functional/getChildrenOrganizations/${parentOrganizationCode}`, {
        method: 'GET'
    });
}

// 图形视图, 批量保存更改
export function batchSaveOrganizationChange(param) {
    return request('/api/oa/workflow/organization/v1/batchsaveorganization', {
        data: param,
        method: 'POST'
    });
}

export function fetchRank(param) {
    return request(`/api/org/v1/rank/${param}`, {
        method: 'GET'
    });
}

export function fetchDuty(param) {
    return request('/api/org/v1/duty/simple/info/get', {
        data: param,
        method: 'POST'
    });
}

// 机构获取主管信息
export function fetchLeader(param) {
    return request(`/api/org/leaderSetting/v1/${param}/leader`, {
        method: 'GET'
    });
}
// 机构获取主管信息 获取草稿信息
export function fetchLeaderDraft(param) {
    return request('/api/org/leaderSetting/v1/appoint/getLeaderDraft', {
        data: param,
        method: 'POST'
    });
}

// 设置主管（草稿）
export function saveLeaderDraft(param) {
    return request('/api/org/leaderSetting/v1/appoint/flow/draft', {
        method: 'POST',
        data: param
    });
}
// 设置主管（提交）
export function submitLeader(param) {
    return request('/api/oa/leaderSetting/v1/appoint/flow/submit', {
        method: 'POST',
        data: param
    });
}

// 获取当前权限下的所有员工信息
export function getEmployeeList(param) {
    return request('/api/oa/leaderSetting/v1/getEmployeeList', {
        method: 'POST',
        data: param
    });
}
// 通过机构、员工编号判断是不是该公司主管岗位员工
export function getOrganizationHaveLeader(param) {
    return request(
        `/api/org/leaderSetting/v1/findOrganizationHaveLeader/${param.organizationCode}/${param.employeeCode}`,
        {
            method: 'GET'
        }
    );
}

// 通过机构Code 返回该机构下的机构岗位树以及员工信息
export function getEmployeeOrgTree(organizationCode) {
    return request(`/api/org/v1/organization/employeeOrgTree/${organizationCode}`, {
        method: 'POST'
    });
}

// 通过机构Code 查询剔除该机构树后剩余机构树
export function getLastOrgTree(organizationCode) {
    return request(`/api/uc/org/v1/organization/lastOrgTree/${organizationCode}`, {
        method: 'POST'
    });
}
